package com.zzyq.pc.web.report.serviceImpl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zzyq.pc.common.enums.Channel;
import com.zzyq.pc.common.enums.StarLevel;
import com.zzyq.pc.common.plugin.db.PageView;
import com.zzyq.pc.common.plugin.shiro.TokenManager;
import com.zzyq.pc.mongodb.dao.MongodbReport;
import com.zzyq.pc.mongodb.model.MongodbDate;
import com.zzyq.pc.utils.LoggerUtils;
import com.zzyq.pc.web.analysis.service.IAnalysisService;
import com.zzyq.pc.web.configure.service.IInformationService;
import com.zzyq.pc.web.report.base.TableField;
import com.zzyq.pc.web.report.mapper.ReportMapper;
import com.zzyq.pc.web.report.model.Report;
import com.zzyq.pc.web.report.response.ModuleData;
import com.zzyq.pc.web.report.service.IReportService;

@Service
public class ReportServiceImpl implements IReportService {

	MongodbReport mr = new MongodbReport();

	@Autowired
	private IInformationService informationService;
	@Autowired
	private ReportMapper reportMapper;
	@Autowired
	private IAnalysisService analysisService;

	/**
	 * 返回任意星级段的舆情信息(只查询敏感方案)
	 * 
	 * @param bigthenNum
	 *            设定的 < 最大转载数
	 * @param lessthenNum
	 *            设定的 >= 最小转载数
	 * @param report_id
	 *            报告ID
	 * @return List<MongodbDate>集合 按星级排序
	 */
	@Override
	public List<MongodbDate> getDataByStarLevel(Integer bigthenNum, Integer lessthenNum, Integer report_id) {
		// 从session 对话请求中获取用户的团体ID
		Integer companyId = TokenManager.getUser().getCompany().getCompanyId();
		if (companyId != null) {
			// 通过团体ID查询用户所属的敏感方案ID并放入List集合中
			List<String> negativeIfmIds = new ArrayList<String>();
			List<Integer> intlist = informationService.selectSensitiveIDsByCompanyId(companyId);
			if (intlist != null && !intlist.isEmpty()) {
				for (Integer integer : intlist) {
					negativeIfmIds.add(integer.toString());
				}
			}
			if (negativeIfmIds == null || negativeIfmIds.isEmpty()) {
				return null;// 方案ID为空 直接返回NULL
			}

			// 获取报告的时间
			Report report = reportMapper.selectByPrimaryKey(report_id);
			if (report != null) {
				// 处理时间
				DateTime dt = new DateTime(report.getCreateTime());
				Long endTime = dt.withMillisOfDay(0).getMillis();
				Long startTime = dt.minusDays(1).withMillisOfDay(0).getMillis();
				return mr.warning(MongodbDate.class, negativeIfmIds, bigthenNum, lessthenNum, startTime, endTime);
			}
			LoggerUtils.debug(getClass(), "报告不存在,ID：" + report_id);
		}
		LoggerUtils.debug(getClass(), "团体ID不存在");
		return null;
	}

	/**
	 * 计算环比参数返回报告对象
	 * 
	 * @param lastNumber
	 *            上期总数
	 * @param lastPositiveNumber
	 *            上期正面数
	 * @param lastNegativeNumber
	 *            上期负面数
	 * @return Report报告对象
	 */
	@Override
	public Report getTodayReport(Integer lastNumber, Integer lastPositiveNumber, Integer lastNegativeNumber,
			Integer companyId) {
		if (null == companyId) {
			// 从session 对话请求中获取用户的团体ID
			companyId = TokenManager.getUser().getCompany().getCompanyId();
		}
		if (companyId != null) {
			// 通过团体ID查询用户所属的方案ID并放入List集合中
			List<String> allIfmIds = new ArrayList<String>();
			List<Integer> intlist = informationService.selectIDsBycompanyId(companyId);
			if (intlist != null && !intlist.isEmpty()) {
				for (Integer integer : intlist) {
					allIfmIds.add(integer.toString());
				}
			}
			if (allIfmIds == null || allIfmIds.isEmpty()) {
				LoggerUtils.debug(getClass(), "团体ID:+" + companyId + "下没有方案，将生成空数据报告！");
				allIfmIds.add("0");
				return mr.getTodayReport(MongodbDate.class, allIfmIds, allIfmIds, lastNumber, lastPositiveNumber,
						lastNegativeNumber, companyId);// 由于团体下如果没有方案的话可能需要生成空数据报告所以在这里不返回null
				// return null;// 方案ID为空 直接返回NULL
			}
			// 将敏感方案ID 再次加入新的List 集合中
			List<String> negativeIfmIds = new ArrayList<String>();
			List<Integer> minList = informationService.selectSensitiveIDs(intlist);
			if (minList != null && !minList.isEmpty()) {
				for (Integer integer : minList) {
					negativeIfmIds.add(integer.toString());
				}
			}
			return mr.getTodayReport(MongodbDate.class, allIfmIds, negativeIfmIds, lastNumber, lastPositiveNumber,
					lastNegativeNumber, companyId);
		}
		LoggerUtils.debug(getClass(), "团体ID不存在");
		return null;
	}

	/**
	 * 查询当前报告上一期报告 仅用做预览和导出时了解昨日环比
	 * 
	 * @param reportId
	 *            当前报告ID
	 * @param companyId
	 *            报告所属团体ID
	 * @param thisreportTime
	 *            报告日期
	 * @return
	 */
	@Override
	public Report selectReportByReportIdAndCompanyId(Integer reportId, Integer companyId, Date thisreportTime) {
		if (null != reportId && null != companyId) {
			Report report = reportMapper.selectReportByReportIdAndCompanyId(reportId, companyId);
			DateTime dt1 = new DateTime(thisreportTime).minusDays(1).withMillisOfDay(0);
			if (null != report) {
				// 判断上期报告日期是否是昨日
				if (report.getReportTime().compareTo(dt1.toDate()) == 0) {// 两个时间相等说明取对了
					return report;
				}
			}
			// 取错了或者上期为null 这种情况正式环境基本不存在
			// 重新统计昨天的
			// 通过团体ID查询用户所属的方案ID并放入List集合中
			DateTime dt = new DateTime(thisreportTime).minusDays(2).withMillisOfDay(0);// 当前报告前两天的零点
			List<String> allIfmIds = new ArrayList<String>();
			List<Integer> intlist = informationService.selectIDsBycompanyId(companyId);
			if (intlist != null && !intlist.isEmpty()) {
				for (Integer integer : intlist) {
					allIfmIds.add(integer.toString());
				}
			}
			if (allIfmIds == null || allIfmIds.isEmpty()) {
				return null;// 方案ID为空 直接返回NULL
			}
			// 将敏感方案ID 再次加入新的List 集合中
			List<String> negativeIfmIds = new ArrayList<String>();
			List<Integer> minList = informationService.selectSensitiveIDs(intlist);
			if (minList != null && !minList.isEmpty()) {
				for (Integer integer : minList) {
					negativeIfmIds.add(integer.toString());
				}
			}
			Report r = mr.getReportNum(MongodbDate.class, allIfmIds, negativeIfmIds, dt.getMillis(),
					dt.plusDays(1).getMillis());
			Report r1 = mr.getlastdayReport(MongodbDate.class, allIfmIds, negativeIfmIds,
					r.getTotal() != null ? r.getTotal() : null, r.getPositiveNum() != null ? r.getPositiveNum() : null,
					r.getNegativeNum() != null ? r.getNegativeNum() : null, companyId, dt1.getMillis(),
					dt1.plusDays(1).getMillis());
			return r1;
		}
		LoggerUtils.debug(getClass(), "团体ID或报告为NULL");
		return null;
	}

	/**
	 * 实时统计本期数据信息
	 * 
	 * @param reportTime
	 * @param company_id
	 * @return
	 */
	public Report realTimeReport(Date reportTime, Integer company_id) {
		if (null != reportTime) {
			DateTime dt = new DateTime(reportTime);
			DateTime startTime = dt.minusDays(1).withMillisOfDay(0);// 头一天的零点
			DateTime endTime = dt.withMillisOfDay(0);// 报告时间的零点
			List<String> allIfmIds = new ArrayList<String>();
			List<Integer> intlist = informationService.selectIDsBycompanyId(company_id);
			if (intlist != null && !intlist.isEmpty()) {
				for (Integer integer : intlist) {
					allIfmIds.add(integer.toString());
				}
			}
			// 将敏感方案ID 再次加入新的List 集合中
			List<String> negativeIfmIds = new ArrayList<String>();
			List<Integer> minList = informationService.selectSensitiveIDs(intlist);
			if (minList != null && !minList.isEmpty()) {
				for (Integer integer : minList) {
					negativeIfmIds.add(integer.toString());
				}
			}
			Report r = mr.getReportNum(MongodbDate.class, allIfmIds, negativeIfmIds, startTime.getMillis(),
					endTime.getMillis());// 查询上期报告的三个数
			// 获取实时本期数据
			return mr.getTodayReport2(MongodbDate.class, allIfmIds, negativeIfmIds, r.getTotal(), r.getPositiveNum(),
					r.getNegativeNum(), company_id, endTime.plusDays(1), endTime);
		}
		return null;
	}

	/**
	 * 新增报告
	 * 
	 * @param report
	 * @return
	 */
	@Override
	public boolean insertReport(Report report) {
		return reportMapper.insert(report) > 0;
	}

	/**
	 * 报告列表查询
	 * 
	 * @param pageView
	 *            分页对象
	 * @param companyId
	 *            团体ID
	 * @return List<Report> 对象
	 */
	@Override
	public List<Report> selectByCompanyId(PageView pageView) {
		// 从session 对话请求中获取用户的团体ID
		Integer companyId = TokenManager.getUser().getCompany().getCompanyId();
		if (null != companyId) {
			Map<String, Object> map = new HashMap<>();
			map.put("paging", pageView);
			map.put("companyId", companyId);
			return reportMapper.selectByCompanyId(map);
		}
		LoggerUtils.debug(getClass(), "团体ID为NULL");
		return null;
	}

	@Override
	public Report selectByPrimaryKey(Integer reportId) {
		if (null != reportId) {
			return reportMapper.selectByPrimaryKey(reportId);
		}
		LoggerUtils.debug(getClass(), "reportId为NULL");
		return null;
	}

	/**
	 * 报告预览
	 * 
	 * @param reportId
	 * @return 三大星级维度List + 两日环比
	 */
	@Override
	public Map<String, Object> selectOneReport(Integer reportId) {
		Map<String, Object> reportDataMap = new HashMap<String, Object>();
		List<MongodbDate> earlyWarningList = new ArrayList<MongodbDate>();// 预警舆情集合
		List<MongodbDate> HighRiskList = new ArrayList<MongodbDate>();// 高危舆情集合
		List<MongodbDate> negativeWarningList = new ArrayList<MongodbDate>();// 负面舆情集合
		List<Report> reportList = new ArrayList<Report>();// 报告对象集合
		Map<String, Integer> typeNum = new HashMap<String, Integer>();// 舆情分布图数据
		List<MongodbDate> list = null;
		// 环比数据
		Report thisreport = selectByPrimaryKey(reportId);// 本期环比数据
		if (null == thisreport) {
			return null;
		}
		// 这里需要重新统计本期数据信息否则数据还是早上八点统计的数据
		Report realTimeReport = realTimeReport(thisreport.getReportTime(), thisreport.getCompanyId());
		// 修改报告表保持报告表是最新数据
		// 并且这里修改后可保证导出的数据与预览的数据一致不会随实时分发影响。且在导出的逻辑代码中不需要改动任何东西比如上面的重新统计就不需要进行，提升导出的性能
		realTimeReport.setReportId(thisreport.getReportId());
		updateByPrimaryKey(realTimeReport);
		// ----------饼图-------------------------
		DateTime dt = new DateTime(thisreport.getReportTime()).withMillisOfDay(0);// 开始时间
		DateTime dt1 = dt.plusDays(1);// 结束时间
		Set<String> types = new HashSet<String>();
		types.add(Channel.BBS.getName());
		types.add(Channel.WEIBO.getName());
		types.add(Channel.NEWS.getName());
		types.add(Channel.WEIXIN.getName());
		typeNum = analysisService.distribution(MongodbDate.class, dt.toString("yyyy-MM-dd"), dt1.toString("yyyy-MM-dd"),
				types);
		// ----------饼图-------------------------
		reportList.add(realTimeReport);
		Report lastreport = selectReportByReportIdAndCompanyId(reportId, thisreport.getCompanyId(),
				thisreport.getReportTime());// 上期环比数据
		// 这里也做一次重新统计保证数据实时性保证环比算法准确性
		Report realTimeReport2 = realTimeReport(lastreport.getReportTime(), lastreport.getCompanyId());
		// 修改报告表保持报告表是最新数据
		// 并且这里修改后可保证导出的数据与预览的数据一致不会随实时分发影响。且在导出的逻辑代码中不需要改动任何东西比如上面的重新统计就不需要进行，提升导出的性能
		realTimeReport2.setReportId(lastreport.getReportId());
		updateByPrimaryKey(realTimeReport2);
		reportList.add(realTimeReport2);
		reportDataMap.put("reportList", reportList);

		list = getMongodbDate(reportId);

		// 查询三个集合数据
		// earlyWarningList =
		// getDataByStarLevel(StarLevel.limitlessStar.getIndex(),
		// StarLevel.FiveStar.getIndex(),
		// reportId);
		// HighRiskList = getDataByStarLevel(StarLevel.FiveStar.getIndex(),
		// StarLevel.ThreeStar.getIndex(), reportId);
		// negativeWarningList =
		// getDataByStarLevel(StarLevel.ThreeStar.getIndex(),
		// StarLevel.OneStar.getIndex(),
		// reportId);
		if (null != list && list.size() > 0 && !list.isEmpty()) {
		earlyWarningList = mr.warningEllipsis(list, StarLevel.limitlessStar.getIndex(), StarLevel.FiveStar.getIndex());
		HighRiskList = mr.warningEllipsis(list, StarLevel.FiveStar.getIndex(), StarLevel.ThreeStar.getIndex());
		negativeWarningList = mr.warningEllipsis(list, StarLevel.ThreeStar.getIndex(), StarLevel.OneStar.getIndex());
		}
		reportDataMap.put("earlyWarningList", earlyWarningList);
		reportDataMap.put("HighRiskList", HighRiskList);
		reportDataMap.put("negativeWarningList", negativeWarningList);
		reportDataMap.put("typeNumber", typeNum);
		return reportDataMap;
	}

	/**
	 * 生成对应团体报告 此方法仅用于定时任务调用 否则时间段会有误差
	 * 
	 * @param companyId
	 * @return
	 */
	@Override
	public boolean creatReport(Integer companyId) {
		// 如果生成过则不在重复生成
		if (selectRepeatReport(companyId, new DateTime().minusDays(1).withMillisOfDay(0).toDate())) {
			LoggerUtils.debug(getClass(), "团体ID：" + companyId + "正在生成重复报告已被拦截！");
			return false;
		}
		DateTime dt = new DateTime().minusDays(2).withMillisOfDay(0);// 头两天的零点
		Report lastReport = selectMaxReport(companyId);// 查询数据库中存储的团体最新报告
		if (null != lastReport) {
			if (lastReport.getReportTime().compareTo(dt.toDate()) == 0) {// 两个时间相等说明取对了
				Report report = getTodayReport(lastReport.getTotal() != null ? lastReport.getTotal() : null,
						lastReport.getPositiveNum() != null ? lastReport.getPositiveNum() : null,
						lastReport.getNegativeNum() != null ? lastReport.getNegativeNum() : null, companyId);
				return insertReport(report);
			}
			// 取错了 这种情况正式环境基本不存在
			// 重新统计前天的
			// 通过团体ID查询用户所属的方案ID并放入List集合中
			List<String> allIfmIds = new ArrayList<String>();
			List<Integer> intlist = informationService.selectIDsBycompanyId(companyId);
			if (intlist != null && !intlist.isEmpty()) {
				for (Integer integer : intlist) {
					allIfmIds.add(integer.toString());
				}
			}
			if (allIfmIds == null || allIfmIds.isEmpty()) {
				Report report = getTodayReport(null, null, null, companyId);
				return insertReport(report);// 如果公司没有一个方案也生成一个空数据报告
				// return false;// 方案ID为空 直接返回NULL
			}
			// 将敏感方案ID 再次加入新的List 集合中
			List<String> negativeIfmIds = new ArrayList<String>();
			List<Integer> minList = informationService.selectSensitiveIDs(intlist);
			if (minList != null && !minList.isEmpty()) {
				for (Integer integer : minList) {
					negativeIfmIds.add(integer.toString());
				}
			}
			Report r = mr.getReportNum(MongodbDate.class, allIfmIds, negativeIfmIds, dt.getMillis(),
					dt.plusDays(1).getMillis());
			Report report = getTodayReport(r.getTotal() != null ? r.getTotal() : null,
					r.getPositiveNum() != null ? r.getPositiveNum() : null,
					r.getNegativeNum() != null ? r.getNegativeNum() : null, companyId);
			return insertReport(report);
		} else {
			// 运行到这里说明此团体第一次生成报告或者之前的报告被清空了
			Report report = getTodayReport(null, null, null, companyId);
			if (null != report) {
				return insertReport(report);
			} else {
				return false;
			}
		}
	}

	/**
	 * 获取团队在数据库中最新的报告
	 * 
	 * @param companyId
	 * @return
	 */
	@Override
	public Report selectMaxReport(Integer companyId) {
		if (companyId != null) {
			return reportMapper.selectMaxReport(companyId);
		}
		return null;
	}

	/**
	 * 处理模块数据
	 */
	@Override
	public void analyzeDisplayData(ModuleData moduleData, List<MongodbDate> earlyWarningList,
			List<MongodbDate> HighRiskList, List<MongodbDate> negativeWarningList, List<Report> reportList) {
		switch (moduleData.getId()) {
		case 1:
			// 开头文字总结
			summary(moduleData, earlyWarningList.size(), HighRiskList.size(), negativeWarningList.size(), reportList);
			break;
		case 2:
			// 预警舆情
			earlyWarning(moduleData, earlyWarningList);
			break;
		case 3:
			// 高危舆情
			HighRisk(moduleData, HighRiskList);
			break;
		case 4:
			// 负面舆情
			negativeWarning(moduleData, negativeWarningList);
			break;
		case 5:
			// 来源分析

			break;
		case 6:
			// 环比
			mom(moduleData, reportList);
			break;
		}
	}

	private void summary(ModuleData moduleData, Integer earlyWarningList, Integer HighRiskList,
			Integer negativeWarningList, List<Report> reportList) {
		String text = moduleData.getText();
		if (!reportList.isEmpty()) {
			text = text.replace("{#sumNum#}",
					reportList.get(0).getTotal() != null ? reportList.get(0).getTotal().toString() : "0")
					.replace("{#positiveNum#}",
							reportList.get(0).getPositiveNum() != null ? reportList.get(0).getPositiveNum().toString()
									: "0")
					.replace("{#negativeNum#}",
							reportList.get(0).getNegativeNum() != null ? reportList.get(0).getNegativeNum().toString()
									: "0")
					.replace("{#earlyWarningNum#}", earlyWarningList + "").replace("{#highRiskNum#}", HighRiskList + "")
					.replace("{#negativeWarningNum#}", negativeWarningList + "");
			moduleData.setText(text);
		} else {
			moduleData.setText("");
			moduleData.clearDataList();
		}
	}

	private void earlyWarning(ModuleData moduleData, List<MongodbDate> earlyWarningList) {
		if (earlyWarningList.size() > 0 && earlyWarningList.get(0) != null) {
			moduleData.addDataList(moduleData.getTitle(), earlyWarningList);
		}
		// 加入表格标题 的字段说明
		if (moduleData.getTypeId() == 2) {
			moduleData.addTableField(
					new TableField("序号", null, moduleData.getTitle(), 0.1F, null, null, true, null, true))
					.addTableField(
							new TableField("标题", "title", moduleData.getTitle(), 0.3F, "url", null, false, null, false))
					.addTableField(new TableField("来源", "websiteName", moduleData.getTitle(), 0.1F, null, null, true,
							null, false))
					.addTableField(
							new TableField("作者", "author", moduleData.getTitle(), 0.1F, null, null, true, null, false))
					.addTableField(new TableField("时间", "releaseTime", moduleData.getTitle(), 0.15F, null, null, true,
							null, false))
					.addTableField(new TableField("转载数", "reprintNumb", moduleData.getTitle(), 0.1F, null, null, true,
							null, false))
					.addTableField(new TableField("星级", "starLevel", moduleData.getTitle(), 0.15F, null, null, true,
							null, false));
		}
	}

	private void HighRisk(ModuleData moduleData, List<MongodbDate> HighRiskList) {
		if (HighRiskList.size() > 0 && HighRiskList.get(0) != null) {
			moduleData.addDataList(moduleData.getTitle(), HighRiskList);
		}
		// 加入表格标题 的字段说明
		if (moduleData.getTypeId() == 2) {
			moduleData.addTableField(
					new TableField("序号", null, moduleData.getTitle(), 0.1F, null, null, true, null, true))
					.addTableField(
							new TableField("标题", "title", moduleData.getTitle(), 0.3F, "url", null, false, null, false))
					.addTableField(new TableField("来源", "websiteName", moduleData.getTitle(), 0.1F, null, null, true,
							null, false))
					.addTableField(
							new TableField("作者", "author", moduleData.getTitle(), 0.1F, null, null, true, null, false))
					.addTableField(new TableField("时间", "releaseTime", moduleData.getTitle(), 0.15F, null, null, true,
							null, false))
					.addTableField(new TableField("转载数", "reprintNumb", moduleData.getTitle(), 0.1F, null, null, true,
							null, false))
					.addTableField(new TableField("星级", "starLevel", moduleData.getTitle(), 0.15F, null, null, true,
							null, false));
		}
	}

	private void negativeWarning(ModuleData moduleData, List<MongodbDate> negativeWarningList) {
		if (negativeWarningList.size() > 0 && negativeWarningList.get(0) != null) {
			moduleData.addDataList(moduleData.getTitle(), negativeWarningList);
		}
		// 加入表格标题 的字段说明
		if (moduleData.getTypeId() == 2) {
			moduleData.addTableField(
					new TableField("序号", null, moduleData.getTitle(), 0.1F, null, null, true, null, true))
					.addTableField(
							new TableField("标题", "title", moduleData.getTitle(), 0.3F, "url", null, false, null, false))
					.addTableField(new TableField("来源", "websiteName", moduleData.getTitle(), 0.1F, null, null, true,
							null, false))
					.addTableField(
							new TableField("作者", "author", moduleData.getTitle(), 0.1F, null, null, true, null, false))
					.addTableField(new TableField("时间", "releaseTime", moduleData.getTitle(), 0.15F, null, null, true,
							null, false))
					.addTableField(new TableField("转载数", "reprintNumb", moduleData.getTitle(), 0.1F, null, null, true,
							null, false))
					.addTableField(new TableField("星级", "starLevel", moduleData.getTitle(), 0.15F, null, null, true,
							null, false));
		}
	}

	private void mom(ModuleData moduleData, List<Report> reportList) {
		if (reportList.size() > 0 && reportList.get(0) != null) {
			moduleData.addDataList(moduleData.getTitle(), reportList, 1);// 重载的
		}
		// 加入表格标题 的字段说明
		if (moduleData.getTypeId() == 2) {
			moduleData
					.addTableField(new TableField("统计时间", "reportName", moduleData.getTitle(), 0.15F, null, null, true,
							null, false))
					.addTableField(new TableField("整体数量", "total", moduleData.getTitle(), 0.15F, null, null, true, null,
							false))
					.addTableField(new TableField("环比增长", "totalCompare", moduleData.getTitle(), 0.15F, null, null,
							true, "%", false))
					.addTableField(new TableField("正面信息", "positiveNum", moduleData.getTitle(), 0.15F, null, null, true,
							null, false))
					.addTableField(new TableField("环比增长", "positiveCompare", moduleData.getTitle(), 0.15F, null, null,
							true, "%", false))
					.addTableField(new TableField("负面信息", "negativeNum", moduleData.getTitle(), 0.15F, null, null, true,
							null, false))
					.addTableField(new TableField("环比增长", "negativeCompare", moduleData.getTitle(), 0.15F, null, null,
							true, "%", false));
		}
	}

	@Override
	public boolean updateByPrimaryKey(Report record) {
		return reportMapper.updateByPrimaryKey(record) > 0;
	}

	@Override
	public List<MongodbDate> getMongodbDate(Integer reportId) {
		List<MongodbDate> list = null;
		// 从session 对话请求中获取用户的团体ID
		Integer companyId = TokenManager.getUser().getCompany().getCompanyId();
		if (companyId != null) {
			// 通过团体ID查询用户所属的敏感方案ID并放入List集合中
			List<String> negativeIfmIds = new ArrayList<String>();
			List<Integer> intlist = informationService.selectSensitiveIDsByCompanyId(companyId);
			if (intlist != null && !intlist.isEmpty()) {
				for (Integer integer : intlist) {
					negativeIfmIds.add(integer.toString());
				}
			}
			if (negativeIfmIds == null || negativeIfmIds.isEmpty()) {

				return null;// 方案ID为空 直接返回NULL
			}

			// 获取报告的时间
			Report report = reportMapper.selectByPrimaryKey(reportId);
			if (report != null) {
				DateTime dt = new DateTime(report.getReportTime()).withMillisOfDay(0);// 开始时间
				DateTime dt1 = dt.plusDays(1);// 结束时间
				// 处理时间
				Long endTime = dt1.withMillisOfDay(0).getMillis();
				Long startTime = dt.withMillisOfDay(0).getMillis();
				list = mr.getWarningList(MongodbDate.class, negativeIfmIds, startTime, endTime);
			}
		}
		return list;
	}

	@Override
	public boolean selectRepeatReport(Integer companyId, Date reportTime) {
		return reportMapper.selectRepeatReport(companyId, reportTime) > 0;
	}

}
